var cDate = new Date();
var cTime = [String(cDate.getFullYear()),
    String(cDate.getMonth()+1),
    String(cDate.getDate()),
    String(cDate.getHours()),
    String(cDate.getMinutes()),
    String(cDate.getSeconds())];


$(document).ready(function() {
    $(window).resize(function() {
        myChart.resize();
    });
});

var myChart = echarts.init(document.getElementById("main_1"));


$.get("DataServlet?type=hour", function(data,status){
	//alert(data);
	var jsonObj = eval('(' + data + ')');
	
	option = {
		title : {
	        text: "最近一小时温度 - "+cTime[0]+"-"+cTime[1]+"-"+cTime[2],
			x: 'center',
	      	y: 0,
	      	textStyle: {
	      		color: 'white',
	      	}
	    },
	    tooltip: {
	    	show: true,
	    	showContent: true,
	        trigger: 'item',
	    },
	    xAxis: {
	    	name: "日期",
	    	type: 'category',
	    	axisLine: {
            	lineStyle: {
            		color: '#686A7F',
            		width: 2,
            	},
            },
            axisTick: {
            	show: false,
            	inside: true,
            	length: 3,
            },
            axisLabel: {
            	textStyle: {
            		fontWeight: 'bolder',
            	}
            },
            data: jsonObj.date
	    },
	    yAxis: {
	    	name: "温度",
	    	type : 'value',
            min: 10,
            max: 30,
            axisTick: {
            	show: false,
            	inside: true,
            	length: 3,
            },
            axisLabel: {
            	textStyle: {
            		fontWeight: 'bolder',
            	}
            },
            axisLine: {
            	lineStyle: {
            		color: '#686A7F',
            		width: 2,
            	},
            },
            splitNumber: 20
	    },
	    series: [{
	        name: '温度',
	        type: 'line',
	        data: jsonObj.temp,
	        smooth: true
	    }]
	};
	myChart.setOption(option);
});